#!/bin/bash
#
# Copyright(c) 2012-2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#

# The line below specified that line under it should be used as the test's short description when launching test via run_tests script.
# The text should not be longer than 80 chars - if it is, the script will strip addititonal characters
# DESCRIPTION Validate spelling of help in CLI

# USE_IN_BVT
# USE_IN_NIGHTLY

# Standard beginning for every test - get the main tests directory and
# link the cas_lib file for CAS API, then use "start_test $*" to pass params
# and do other necessary checks and setup
TESTS_DIR="$(dirname $0)/../"
. $TESTS_DIR/cas_lib
start_test $*

FAIL=0

PERSONAL_DICTIONARY=`pwd`/cas_ex.en.pws

run_aspell() {
  run_cmd "$1 2>&1 | aspell list --lang=en_US --add-extra-dicts=$PERSONAL_DICTIONARY"
  for N in $OUTPUT ; do
    if [ -n $N ] ; then
      FAIL=1
      error "Misspelled word: $N"
    fi
  done
}

run_aspell "$CAS -H"

COMMANDS=`$CAS -H | awk '/Available commands:/{ cmd=1;next } /For detailed help/ { cmd=0 } cmd { print $0 }' | grep -o '\-\-\S*'`

for CMD in $COMMANDS ; do
  run_aspell "$CAS $CMD -H"
done

end_test $FAIL
